﻿using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DefCore
{

    public sealed class ResourceBin
    {
        //Singleton Pattern
        private static ResourceBin _Instance;
        public static ResourceBin Instance
        {
            get
            {
                if (_Instance == null)
                    _Instance = new ResourceBin();

                return _Instance;
            }
        }

        //Fields
        private Dictionary<string, object> _ResourceBank;

        //ctor
        protected ResourceBin()
        {
            _ResourceBank = new Dictionary<string, object>();

        }

        //Methods
        public void Load()
        {
            _ResourceBank.Clear();

            //Todo: Add Sprite Loading Here            
            _ResourceBank.Add("ASSET_TEXTUREPAK", LoadAsset<Texture2D>("src/ASSETPAK01/ASSETPAK01_TEXTURE"));
            _ResourceBank.Add("actorstatecircle", LoadAsset<Texture2D>("src/ASSETPAK01/ASSETPAK01_STATECIRCLE"));
            _ResourceBank.Add("frameindicator", LoadAsset<Texture2D>("src/ASSETPAK01/ASSETPAK01_FRAME"));

            _ResourceBank.Add("FRAMEWALL_NS", SpriteSheetHelper.Retreive(Get<Texture2D>("frameindicator"), new Rectangle(0, 0, 96, 15)));
            _ResourceBank.Add("FRAMEWALL_EW", SpriteSheetHelper.Retreive(Get<Texture2D>("frameindicator"), new Rectangle(0, 15, 15, 96)));
            _ResourceBank.Add("FRAMEWALL_CN", SpriteSheetHelper.Retreive(Get<Texture2D>("frameindicator"), new Rectangle(15, 15, 66, 66)));
            
            SpriteSheetHelper.OverrideBackgroundColor = new Color(0xff, 0xff, 0xff, 0x00);
            _ResourceBank.Add("ASSET_SELECTOR", SpriteSheetHelper.Retreive(ResourceBin.Instance.Get<Texture2D>("ASSET_TEXTUREPAK"), new Rectangle(512, 256, 256, 256), true));


            //AGENTS
            _ResourceBank.Add("AGENT_WORKER", LoadAsset<Texture2D>("src/ASSETPAK01/ASSETPAK01_AGENTWORKER"));
            _ResourceBank.Add("AGENT_GHAST", LoadAsset<Texture2D>("src/ASSETPAK01/ASSETPAK01_AGENTGHAST"));

            //STRUCTURES
            _ResourceBank.Add("STRUCT_LANTERN", LoadAsset<Texture2D>("src/ASSETPAK01/ASSETPAK01_STRLANTERN"));
            _ResourceBank.Add("STRUCT_WOODBRIDGE", LoadAsset<Texture2D>("src/ASSETPAK01/ASSETPAK01_WOODBRIDGE"));

            //UI        
        }

        public T Get<T>(string name)
        {
            return (T)_ResourceBank[name];
        }
        private T LoadAsset<T>(string file)
        {
            return (T)Objects.GameObject.Content.Load<T>(file);
        }
    }
}
